package com.moon.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.moon.dao.TAuctionItemMapper;
import com.moon.entity.TAuctionItem;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class TAuctionItemService {
    @Autowired
    private TAuctionItemMapper tAuctionItemMapper;

    public List<TAuctionItem> queryTAuctionItem(Long id,Integer currentPage,Integer pageSize) {
        Example example=new Example(TAuctionItem.class);//要查询的表对应的实体类
//        example.orderBy("createTime"); 对象属性名升序
        example.setOrderByClause("create_time DESC"); //根据字段名进行排序
        Example.Criteria criteria=example.createCriteria();//创建查询标准
        criteria.andEqualTo("auctionId",id);//调用方法，编写自己想要查询的条件
        int start=(currentPage-1)*pageSize;
        RowBounds rowBounds = new RowBounds(start, pageSize);//分页查询
        return tAuctionItemMapper.selectByExampleAndRowBounds(example,rowBounds);
    }


    /**
     * 按照竞拍室id分页查找竞拍记录明细
     *
     * @param auctionId
     * @param pageNo
     * @param pageSize
     * @return
     */
    public PageInfo<TAuctionItem> getItemByAuctionId(long auctionId , Integer pageNo , Integer pageSize) {
        TAuctionItem item = new TAuctionItem();
        item.setAuctionId(auctionId);
        Example example = new Example(TAuctionItem.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("auctionId",auctionId);
        example.setOrderByClause("create_time DESC");
        PageHelper.startPage(pageNo,pageSize);
        List<TAuctionItem> auctionItemList = tAuctionItemMapper.selectByExample(example);
        PageInfo<TAuctionItem> auctionPageList = new PageInfo<>(auctionItemList);


        return auctionPageList;
    }
}
